//
//  WSFindCell.m
//  GroupFourFM
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSFindCell.h"

@interface WSFindCell ()

@property (nonatomic, strong) UIImageView *newsPic;
@property (nonatomic, strong) WSBaseTitleLabel *newsTitle;
@property (nonatomic, strong) UILabel *newsDigest;
@property (nonatomic, strong) UIButton *nextBtn;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation WSFindCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createCell];
        self.isShowLine = NO;
    }
    
    return self;
}

-(void)createCell
{
    self.newsPic = [[UIImageView alloc] init];
    self.newsPic.backgroundColor = CLEAR;
    [self.contentView addSubview:self.newsPic];
    [self.newsPic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@10);
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(@(-5));
        make.width.equalTo(self.contentView.mas_height).offset(-10);
    }];
    
    self.newsTitle = [[WSBaseTitleLabel alloc] init];
    self.newsTitle.backgroundColor = CLEAR;
    self.newsTitle.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
    self.newsTitle.font = [UIFont systemFontOfSize:19];
    [self.contentView addSubview:self.newsTitle];
    [self.newsTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsPic).offset(10);
        make.right.mas_equalTo(@(-40));
        make.height.equalTo(self.newsPic).multipliedBy(0.35);
    }];
    
    self.newsDigest = [[UILabel alloc] init];
    self.newsDigest.backgroundColor = CLEAR;
    self.newsDigest.font = [UIFont systemFontOfSize:16 weight:0];
    [self.contentView addSubview:self.newsDigest];
    self.newsDigest.textColor = [UIColor lightGrayColor];
    self.newsDigest.numberOfLines = 2;
    [self.newsDigest mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsTitle.mas_bottom);
        make.right.equalTo(self.newsTitle);
        make.height.equalTo(self.newsTitle);
    }];
    
    self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nextBtn.backgroundColor = CLEAR;
    [self.nextBtn setImage:[UIImage imageNamed:@"findcell_arrow"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.nextBtn];
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(@(-20));
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(@10);
    }];
    
    self.lineView = [[UIView alloc] init];
    self.lineView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
    [self.contentView addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.newsTitle);
        make.bottom.equalTo(self.contentView);
        make.right.mas_equalTo(@0);
        make.height.mas_equalTo(@1);
    }];
    self.lineView.hidden = !self.isShowLine;
}

-(void)setModel:(WSChildListModel *)model
{
    _model = model;
    self.lineView.hidden = !self.isShowLine;
    NSURL *url = [NSURL URLWithString:model.coverPath];
    [self.newsPic sd_setImageWithURL:url placeholderImage:PLACEHOLDER_CELL_SAME];
    self.newsTitle.text = model.title;
    self.newsDigest.text = model.subtitle;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
